package com.eiss.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.eiss.common.utils.poi.ExcelUtil;
import com.eiss.domain.DTO.TransferstationDTO;
import com.eiss.domain.Entily.Transferstation;
import com.eiss.domain.VO.TransferstationVO;
import com.eiss.service.ITransferstationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.eiss.common.annotation.Log;
import com.eiss.common.core.controller.BaseController;
import com.eiss.common.core.domain.AjaxResult;
import com.eiss.common.enums.BusinessType;
import com.eiss.common.core.page.TableDataInfo;

/**
 * 中转站管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-24
 */
@RestController
@RequestMapping("/system/transferstations")
public class TransferstationController extends BaseController
{
    @Autowired
    private ITransferstationService transferstationService;

    /**
     * 查询中转站管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:transferstations:list')")
    @GetMapping("/list")
    public TableDataInfo list(Transferstation transferstation)
    {
        startPage();
        List<TransferstationDTO> list = transferstationService.selectTransferstationList(transferstation);
        return getDataTable(list);
    }

    /**
     * 导出中转站管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:transferstations:export')")
    @Log(title = "中转站管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Transferstation transferstation)
    {
        List<TransferstationDTO> list = transferstationService.selectTransferstationList(transferstation);
        ExcelUtil<TransferstationDTO> util = new ExcelUtil<TransferstationDTO>(TransferstationDTO.class);
        util.exportExcel(response, list, "中转站管理数据");
    }

    /**
     * 获取中转站管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:transferstations:query')")
    @GetMapping(value = "/{TransferStationID}")
    public AjaxResult getInfo(@PathVariable("TransferStationID") Long TransferStationID)
    {
        return success(transferstationService.selectTransferstationByTransferStationID(TransferStationID));
    }

    /**
     * 新增中转站管理
     */
    @PreAuthorize("@ss.hasPermi('system:transferstations:add')")
    @Log(title = "中转站管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferstationVO transferstation)
    {
        return toAjax(transferstationService.insertTransferstation(transferstation));
    }

    /**
     * 修改中转站管理
     */
    @PreAuthorize("@ss.hasPermi('system:transferstations:edit')")
    @Log(title = "中转站管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferstationVO transferstation)
    {
        return toAjax(transferstationService.updateTransferstation(transferstation));
    }

    /**
     * 删除中转站管理
     */
    @PreAuthorize("@ss.hasPermi('system:transferstations:remove')")
    @Log(title = "中转站管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{TransferStationIDs}")
    public AjaxResult remove(@PathVariable Long[] TransferStationIDs)
    {
        return toAjax(transferstationService.deleteTransferstationByTransferStationIDs(TransferStationIDs));
    }
    @PostMapping("/Nearbystation")
    public AjaxResult Nearbystation(Double x,Double y)
    {
        return success(transferstationService.Nearbystation(x,y));
    }
}
